package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.common.CommonResult;
import com.neuedu.yyzx.entity.Back;
import com.neuedu.yyzx.service.IBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 退住登记  前端控制器
 * </p>
 *
 * @author dya
 * @since 2021-04-27
 */
@RestController
@RequestMapping("//back")
public class BackController {

    @Autowired
    IBackService backService;

    @RequestMapping("/list")
    CommonResult list(Page page, Back back){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        if (back!=null && StringUtils.isNotEmpty(back.getCustomerName())){
            queryWrapper.like("customer_name",back.getCustomerName());
        }
        return CommonResult.success(backService.page(page,queryWrapper));
    }

    @RequestMapping("/add")
    CommonResult add(Back back){
        return CommonResult.success(backService.saveOrUpdate(back));
    }

    @RequestMapping("/getById")
    CommonResult getById(Integer backId){
        return CommonResult.success(backService.getById(backId));
    }

    @RequestMapping("/del")
    CommonResult del(Integer backId){
        UpdateWrapper updateWrapper=new UpdateWrapper();
        updateWrapper.set("is_deleted",1);
        updateWrapper.eq("back_id",backId);
        return CommonResult.success(backService.update(updateWrapper));
    }

}
